//  ---------------  点击提交修改 发送请求--------------------------
$('.xiugai').on('click', function(e) {
    // 阻止页面跳转
    e.preventDefault();
    let data = $('form').serialize();
    // console.log(data);
    // 收集数据之后进行请求发送
    $.ajax({
        type: 'post',
        url: 'http://ajax.frontend.itheima.net/my/userinfo',
        data: data,
        headers: {
            Authorization: localStorage.getItem('token')
        },
        success: function(res) {
            layer.msg(res.message);
            rederForm()
        }
    })

});

//  ---------------  点击重置 回到原来的位置--------------------------
$('.reset').on('click', function(e) {
    e.preventDefault();
    console.log(123)
    rederForm()
})

//  ---------------  渲染页面 数据回流--------------------------
function rederForm() {
    let form = layui.form;
    $.ajax({
        type: 'GET',
        url: 'http://ajax.frontend.itheima.net/my/userinfo',

        headers: {
            Authorization: localStorage.getItem('token')
        },
        success: function(res) {
            console.log(res.data)
                //给表单赋值
            form.val("formTest", res.data);

        }
    })
}
rederForm()